package me.magicall.myblog.base.web.springmvc.interceptors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.core.Ordered;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class SysoutInterceptor implements HandlerInterceptor, Ordered {

	@Override
	public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler) throws Exception {
		System.out.println("@@@@@@next handler:" + handler + " " + request.getRequestURI());
//		System.out.println("@@@@@@" + request.getQueryString());
//		final Map<String, String[]> parameterMap = request.getParameterMap();
//		for (final Entry<String, String[]> e : parameterMap.entrySet()) {
//			final String s = e.getKey();
//			System.out.println("@@@@@@" + s + " " + URLDecoder.decode(s, EncodingConst.GBK));
//			System.out.println("@@@@@@" + Arrays.toString(e.getValue()));
//		}

		return true;
	}

	@Override
	public void afterCompletion(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final Exception ex)
			throws Exception {
	}

	@Override
	public void postHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final ModelAndView modelAndView)
			throws Exception {
//		System.out.println("@@@@@@SysoutInterceptor.postHandle():" + modelAndView);
	}

	@Override
	public int getOrder() {
		return Ordered.HIGHEST_PRECEDENCE;
	}

}
